<template>
  <div class="wrap">
    <!-- tab选项卡 -->
    <div class="tab_contract">
      <li :class="isShow==1?'active':''" @click="changeContract(1)">销售合同</li>
      <li :class="isShow==2?'active':''" @click="changeContract(2)">采购合同</li>
    </div>

    <!-- ---------------------------------销售合同----------------------------------------- -->

    <div class="shop_contract" :class="isShow==1?'contract_isactive':''">
      <div class="header_form">
        <el-form ref="form" :model="saleForm" label-width="80px">
          <el-form-item label="合同编号:">
            <el-input v-model="saleForm.contractNo"></el-input>
          </el-form-item>
          <el-form-item label="甲方名称:">
            <el-input v-model="saleForm.jiaFangCompany"></el-input>
          </el-form-item>
          <el-form-item label="联系人:">
            <el-input v-model="saleForm.jiaFangName"></el-input>
          </el-form-item>
          <el-form-item label="联系方式:" style="clear:both">
            <el-input v-model="saleForm.jiaFangPhone"></el-input>
          </el-form-item>
          <el-form-item label="创建日期:">
            <el-date-picker type="date" placeholder="选择日期" v-model="saleForm.createDate" style="width: 100%;">
            </el-date-picker>
          </el-form-item>
          <el-form-item style="clear:both">
            <el-button type="primary" @click="searchSaleContract">查询</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>

        <!-- 新增新增销售合同按钮 -->
        <div class="add_contract">
          <el-button type="primary">新增销售合同</el-button>
        </div>
      </div>

      <!-- 销售合同表 -->
      <div class="stuff_table">
        <template>
          <el-table :data="contractData" border style="width: 90%">
            <el-table-column type="index" width="50" label="序号">
            </el-table-column>
            <el-table-column prop="number" label="合同编号" width="180">
            </el-table-column>
            <el-table-column prop="contractName" label="合同名称">
            </el-table-column>
            <el-table-column prop="project" label="关联项目">
            </el-table-column>
            <el-table-column prop="money" label="合同金额(万)">
            </el-table-column>
            <el-table-column prop="namePartB" label="乙方名称">
            </el-table-column>
            <el-table-column prop="contacts" label="联系人">
            </el-table-column>
            <el-table-column prop="phone" label="联系方式">
            </el-table-column>
            <el-table-column prop="founder" label="创建人">
            </el-table-column>
            <el-table-column prop="dateTime" label="创建日期">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>

        <!-- 页码 -->
        <div id="pages">
          <el-pagination background layout="prev, pager, next" :current-page="shopCurrentPage" :page-size="shopPageSize"
            :total="shopTotal" @current-change="shopChangeCurrentPage" style="text-align:center;">
          </el-pagination>
        </div>
      </div>
    </div>

    <!-- ------------------------------------------采购合同------------------------------------- -->

    <div class="purchase_contract" :class="isShow==2?'contract_isactive':''">
      <div class="header_form">
        <el-form ref="form" :model="purchase" label-width="80px">
          <el-form-item label="合同编号:">
            <el-input v-model="purchase.contractNo"></el-input>
          </el-form-item>
          <el-form-item label="乙方名称:">
            <el-input v-model="purchase.supplierName"></el-input>
          </el-form-item>
          <el-form-item label="联系人:">
            <el-input v-model="purchase.legalPerson"></el-input>
          </el-form-item>
          <el-form-item label="联系方式:" style="clear:both">
            <el-input v-model="purchase.legalPersonPhone"></el-input>
          </el-form-item>
          <el-form-item label="创建日期:">
            <el-date-picker type="date" placeholder="选择日期" v-model="purchase.createDate" style="width: 100%;">
            </el-date-picker>
          </el-form-item>
          <el-form-item style="clear:both">
            <el-button type="primary" @click="searchPurchaseContract">查询</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>

        <!-- 新增采购合同按钮 -->
        <div class="add_contract">
          <el-button type="primary">新增采购合同</el-button>
        </div>
      </div>

      <!-- 采购合同表 -->
      <div class="stuff_table">
        <template>
          <el-table :data="purchaseData" border style="width: 90%">
            <el-table-column type="index" width="50" label="序号">
            </el-table-column>
            <el-table-column prop="number" label="合同编号" width="180">
            </el-table-column>
            <el-table-column prop="contractName" label="合同名称">
            </el-table-column>
            <el-table-column prop="project" label="关联项目">
            </el-table-column>
            <el-table-column prop="money" label="合同金额(万)">
            </el-table-column>
            <el-table-column prop="namePartB" label="乙方名称">
            </el-table-column>
            <el-table-column prop="contacts" label="联系人">
            </el-table-column>
            <el-table-column prop="phone" label="联系方式">
            </el-table-column>
            <el-table-column prop="founder" label="创建人">
            </el-table-column>
            <el-table-column prop="dateTime" label="创建日期">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>

        <!-- 页码 -->
        <div id="pages">
          <el-pagination background layout="prev, pager, next" :current-page="purchaseCurrentPage"
            :page-size="purchasePageSize" :total="purchaseTotal" @current-change="purchaseChangeCurrentPage"
            style="text-align:center;">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<style src="./style/routineContract.css">
</style>
<script>
import api from "../../../utils/api.js";
export default {
  data () {
    return {
      saleForm: {
        // 合同编号
        contractNo: '',
        // 创建时间
        createDate: '',
        // 甲方名称
        jiaFangCompany: '',
        // 联系人
        jiaFangName: '',
        // 联系方式
        jiaFangPhone: '',
        // 项目ID
        projectId: '',
        // 条数
        pageSize: 10,
        // 当前页
        currentPage: this.shopCurrentPage
      },

      // 采购合同
      purchase: {
        // 合同编号
        contractNo: '',
        // 创建时间
        createDate: '',
        // 乙方名称
        supplierName: '',
        // 联系人
        legalPerson: '',
        // 联系方式
        legalPersonPhone: '',
        // 项目ID
        projectId: '',
        // 条数
        pageSize: 10,
        // 当前页
        currentPage: this.shopCurrentPage
      },
      // 销售合同表
      contractData: [
        {
          number: '',
          contractName: '',
          project: '',
          money: '',
          namePartB: '',
          contacts: '',
          phone: '',
          founder: '',
          dateTime: ''
        }
      ],
      // 采购合同表
      purchaseData: [
        {
          number: '',
          contractName: '',
          project: '',
          money: '',
          namePartB: '',
          contacts: '',
          phone: '',
          founder: '',
          dateTime: ''
        }
      ],
      // 销售合同分页
      shopCurrentPage: 1,
      shopPageSize: 20,
      shopTotal: 50,
      // 采购合同分页
      purchaseCurrentPage: 1,
      purchasePageSize: 20,
      purchaseTotal: 50,
      // tab控制器
      isShow: 1,
    };
  },
  methods: {
    // 销售合同分页
    shopChangeCurrentPage (index) {
      this.shopCurrentPage = index
    },
    // 采购合同分页
    purchaseChangeCurrentPage (index) {
      this.purchaseCurrentPage = index
    },
    // 切换常规合同
    changeContract (index) {
      this.isShow = index
    },
    // ----------------------------api部分------------------------------------------
    // 多条件查询销售合同
    searchSaleContract () {
      api.searchSaleContract(this.saleForm).then(res => {
        if (res.data.code == 200) {
          this.$message.success('查询成功')
        } else {
          this.$message.success(res.data.msg)
        }
      })
    },
    // 多条件查询采购合同
    searchPurchaseContract () {
      api.searchPurchaseContract(this.purchase).then(res => {
        if (res.data.code == 200) {
          this.$message.success('查询成功')
        } else {
          this.$message.success(res.data.msg)
        }
      })
    }
  },
  created () {

  },
  mounted () {

  },
  computed: {

  }
};
</script>

<style scoped lang="less">
</style>
